package com.qgs.secsgem.mq.secsgem;




import com.qgs.secsgem.mq.entity.MQMessage;

import java.util.HashMap;

/**
 * @Desc: "MES端 发送远程指令列表"
 * @Author: caixiang
 * @DATE: 2021/8/17 14:14
 */
public class SendedList {
    private static HashMap<String, AsyncFuture<MQMessage>> list = new HashMap<>();

//    public static synchronized AsyncFuture<MQMessage> get(String transitionId){
//        return list.get(transitionId);
//    }
//    public static synchronized void put(String transitionId,AsyncFuture<MQMessage> asyncFuture){
//        list.put(transitionId,asyncFuture);
//    }

    public static synchronized AsyncFuture<MQMessage> add(String transitionId, MQMessage mqMessageRequest) {

        AsyncFuture<MQMessage> objectAsyncFuture = new AsyncFuture<>(mqMessageRequest);
        list.put(transitionId,objectAsyncFuture);
        return objectAsyncFuture;
    }

    public static synchronized Boolean set(String transitionId, MQMessage message) {
        AsyncFuture<MQMessage> mqMessageAsyncFuture = list.get(transitionId);
        if(mqMessageAsyncFuture == null){
            return false;
        }
        mqMessageAsyncFuture.done(message);
        //清除 ，防止这个hashMap过大。
        list.remove(transitionId);
        return true;
    }
}
